package com.masterclient.app.businessmodule.homemodule.view.adapter.template;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.homemodule.bean.homecms.HomeNewCmsIndexBean;
import com.masterclient.app.businessmodule.homemodule.view.holder.HomeViewHolder;
import com.masterclient.app.utils.CommonUtil;

import java.util.List;


public class HomePageXCollectionAdapter extends DelegateAdapter.Adapter<HomeViewHolder> {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private VirtualLayoutManager.LayoutParams mLayoutParams;
    private int mCount = 0;

    private String brand_list_url;
    private List<HomeNewCmsIndexBean> sh_rem_collection;

    public HomePageXCollectionAdapter(Context context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, null, "",null);
    }

    public HomePageXCollectionAdapter(Context context, LayoutHelper layoutHelper, int count, @NonNull VirtualLayoutManager.LayoutParams layoutParams, String brand_list_url,List<HomeNewCmsIndexBean> sh_rem_collection) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
        this.brand_list_url = brand_list_url;
        this.sh_rem_collection = sh_rem_collection;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @Override
    protected void onBindViewHolderWithOffset(HomeViewHolder holder, int position, int offsetTotal) {
    }

    @Override
    public HomeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(HomeViewHolder holder, int position) {
        if (mLayoutParams != null) {
            holder.itemView.setLayoutParams(
                    new VirtualLayoutManager.LayoutParams(mLayoutParams));
        }

        LinearLayout selected_collection_layout = holder.itemView.findViewById(R.id.selected_collection_layout);
        View viewTitle = holder.itemView.findViewById(R.id.view_title);
        RecyclerView concentrationRecyclerView = holder.itemView.findViewById(R.id.concentrationRecyclerView);
        //为你精选
        if (sh_rem_collection != null) {
            if (sh_rem_collection != null &&
                    sh_rem_collection.size() > 0) {
                selected_collection_layout.setVisibility(View.VISIBLE);
                viewTitle.setVisibility(View.VISIBLE);
                viewTitle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        CommonUtil.goAnyWhere(mContext,brand_list_url,"","","","","");
                    }
                });

                LinearLayoutManager mmLayoutManager = new LinearLayoutManager(mContext);
                concentrationRecyclerView.setLayoutManager(mmLayoutManager);
                ConcentrationProductAdapter concentrationProductAdapter = new ConcentrationProductAdapter(mContext, "首页", sh_rem_collection);
                concentrationRecyclerView.setAdapter(concentrationProductAdapter);
            } else {
                selected_collection_layout.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public int getItemCount() {
        return mCount;
    }

    @Override
    public int getItemViewType(int position) {
        return 3;
    }
}
